<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "audio".
 *
 * @property integer $id
 * @property string $title
 * @property string $description
 * @property string $audio_pic
 * @property string $audio_url
 * @property string $length
 * @property string $ctime
 * @property string $lyric
 * @property string $music_lyric
 * @property string $release_time
 * @property integer $praise_num
 * @property integer $comment_num
 * @property integer $read_times
 * @property integer $anchor_id
 * @property integer $poducer_id
 *
 * @property AudioLabel[] $audioLabels
 * @property Label[] $labels
 * @property Collect[] $collects
 * @property User[] $users
 * @property Comment[] $comments
 * @property Praise[] $praises
 * @property User[] $users0
 */
class Audio extends \yii\db\ActiveRecord {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'audio';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['title', 'description', 'audio_pic', 'audio_url', 'length', 'lyric', 'release_time'], 'required'],
            [['description', 'lyric', 'music_lyric'], 'string'],
            [['length', 'ctime', 'release_time'], 'safe'],
            [['praise_num', 'comment_num', 'read_times', 'anchor_id', 'poducer_id'], 'integer'],
            [['title', 'audio_pic'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => '音频id',
            'title' => '音频标题',
            'description' => '音频简介',
            'audio_pic' => '音频配图',
            'audio_url' => 'mp3地址',
            'length' => '音频时长',
            'ctime' => 'Ctime',
            'lyric' => '稿件',
            'music_lyric' => '音乐歌词',
            'release_time' => '发布时间',
            'praise_num' => '点赞数 ',
            'comment_num' => '评论数',
            'read_times' => '阅读数',
            'anchor_id' => '主播id',
            'poducer_id' => '制作者id',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAudioLabels() {
        return $this->hasMany(AudioLabel::className(), ['audio_id' => 'id'])->inverseOf('audio');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLabels() {
        return $this->hasMany(Label::className(), ['id' => 'label_id'])->viaTable('audio_label', ['audio_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCollects() {
        return $this->hasMany(Collect::className(), ['audio_id' => 'id'])->inverseOf('audio');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsers() {
        return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('collect', ['audio_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getComments() {
        return $this->hasMany(Comment::className(), ['audio_id' => 'id'])->inverseOf('audio');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPraises() {
        return $this->hasMany(Praise::className(), ['audio_id' => 'id'])->inverseOf('audio');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsers0() {
        return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('praise', ['audio_id' => 'id']);
    }
}
